<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 错误的集合 -->
    <script>
      var findErrorNums = function (nums) {
        const errorNums = new Array(2).fill(0)
        const n = nums.length
        nums.sort((a, b) => a - b)
        let prev = 0
        for (let i = 0; i < n; i++) {
          const curr = nums[i]
          if (curr === prev) {
            errorNums[0] = prev
          } else if (curr - prev > 1) {
            errorNums[1] = prev + 1
          }
          prev = curr
        }
        if (nums[n - 1] !== n) {
          errorNums[1] = n
        }
        return errorNums
      }
      console.log(findErrorNums([1, 2, 2, 4]))
    </script>
  </body>
</html>
